package com.example.yls.demoa;

import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements IOnTimeChangeListener {
    private Button btnStart;
    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.e("MainActivity","Thread id="+Thread.currentThread().getId());
        btnStart=findViewById(R.id.btn_start);
        textView=findViewById(R.id.result);
        btnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.setClass(MainActivity.this,MyService.class);
                startService(intent);

                reciver reciver=new reciver(MainActivity.this);
                IntentFilter filter=new IntentFilter();
                filter.addAction("TIME_CHANGE");

                registerReceiver(reciver,filter);



            }
        });
    }

    @Override
    public void show(String str) {
        textView.setText(str);
    }
}
